<template>
  <el-card>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="user_name" label="姓名"> </el-table-column>
      <el-table-column prop="create_time" label="注册日期"> </el-table-column>
      <el-table-column prop="city" label="地址"> </el-table-column>
      <el-table-column prop="admin" label="权限"> </el-table-column>
    </el-table>

    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNum" :page-sizes="[20, 25, 30, 35, 40]" :page-size="limit" layout="total, sizes, prev, pager, next, jumper" :total="count"> </el-pagination>
  </el-card>
</template>

<script>
import { adminCountNum } from '../api/index'
import request from '../api/axiosApi'
export default {
  data() {
    return {
      tableData: [],
      count: null,
      limit: 20,
      offset: 1,
      pageNum: 1
    }
  },
  created() {
    this.initData()
  },
  methods: {
    async initData() {
      try {
        const { data: res } = await adminCountNum()
        if (res.status === 1) {
          this.count = res.count
        } else {
          throw new Error('获取数据失败')
        }
        this.getAdminInfo()
      } catch (error) {
        console.log(error)
      }
    },
    async getAdminInfo() {
      const { data: res } = await request.get(`/admin/all?limit=${this.limit}&offset=${this.offset}`)
      this.tableData = res.data
    },
    handleSizeChange(pageSize) {
      this.limit = pageSize
      this.getAdminInfo()
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum
      this.offset = pageNum * this.limit
      this.getAdminInfo()
    }
  }
}
</script>

<style></style>
